package com.xuzimian.globaldemo.spring.springrpc.webconfig;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * hessian 等远程服务必须用过web http发布，所以这里采用SpringMvc来发布
 * 注意：依赖包中如果有spring-web就无需引入spring-remote包，因为spring-web中本身就包含了spring-remote，
 * 如果引入的spring-remote和server发布版本不一致，有可能导致hessian之类的协议版本不一致。
 */
public class WenInitializer implements WebApplicationInitializer{

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
		webApplicationContext.register(WebSpringConfig.class);
		webApplicationContext.refresh();
		DispatcherServlet dispatcherServlet=new DispatcherServlet(webApplicationContext);

		ServletRegistration.Dynamic dispatcher=servletContext.addServlet("dispatcherServlet",dispatcherServlet);
		dispatcher.setLoadOnStartup(1);
		dispatcher.addMapping("/");
	 	dispatcher.addMapping("*.hessianservice");

	}

}
